<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/3/10
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--导入taglib指令 使用核心库--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>公共页面</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css"  />
    <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js" ></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js" ></script>
</head>
<body>
        <%--包含了logo以及导航条件部分--%>

        <!--
                        描述：菜单栏
                    -->
        <div class="container-fluid">
            <div class="col-md-4">
                <img src="${pageContext.request.contextPath}/img/logo2.png" />
            </div>
            <div class="col-md-5">
                <img src="${pageContext.request.contextPath}/img/header.png" />
            </div>
            <div class="col-md-3" style="padding-top:20px">
                <ol class="list-inline">
                    <%--如果sesison域中的user对象是空--%>
                    <c:if test="${empty user}">
                        <li><a href="${pageContext.request.contextPath}/user?methodName=loginUI">登录</a></li>
                        <!--${pageContext.request.contextPath} 通过pageContext域对象获取request bean属性同时通过
                        request对象获取contextPath这个bean属性,获取上下文路径
                        等价于pageContext.getRequest().getcontextPath()
                        -->
                        <li><a href="${pageContext.request.contextPath}/user?methodName=registerUI">注册</a></li>
                        <li><a href="">购物车</a></li>
                    </c:if>
                    <%--如果session域中的user对象不为空--%>

                    <c:if test="${not empty user}">
                        <stong>欢迎,${user.name}</stong>
                        <li><a href="${pageContext.request.contextPath}/user?methodName=logout">退出</a></li>
                        <li><a href="${pageContext.request.contextPath}/order?methodName=findOrderByPage&currentPage=1&pageSize=3">我的订单列表</a></li>

                    </c:if>

                </ol>
            </div>
        </div>
        <!--
            描述：导航条
        -->
        <div class="container-fluid">
            <nav class="navbar navbar-inverse">
                <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="#">首页</a>
                    </div>

                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav" id="daohangUL">

                            <%--<li class="active"><a href="product_list.htm">手机数码<span class="sr-only">(current)</span></a></li>--%>
                            <%--<li><a href="#">电脑办公</a></li>
                            <li><a href="#">电脑办公</a></li>
                            <li><a href="#">电脑办公</a></li>--%>
                        </ul>
                        <form class="navbar-form navbar-right" role="search">
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="Search">
                            </div>
                            <button type="submit" class="btn btn-default">Submit</button>
                        </form>

                    </div>
                    <!-- /.navbar-collapse -->
                </div>
                <!-- /.container-fluid -->
            </nav>
        </div>




</body>

    <script>
        <%--给服务器发送异步请求--%>
        $.get("${pageContext.request.contextPath}/category?methodName=findAllCategory",
            function (data) {
            //data:服务器响应过来的数据
            /*
            * [{"cid":"1","cname":"手机数码"},
            * {"cid":"172934bd636d485c98fd2d3d9cccd409","cname":"运动户外"},
            * {"cid":"2","cname":"电脑办公"},
            * {"cid":"3","cname":"家具家居"},
            * {"cid":"4","cname":"鞋靴箱包"},
            * {"cid":"5","cname":"图书音像"},
            * {"cid":"59f56ba6ccb84cb591c66298766b83b5","cname":"aaaa"},
            * {"cid":"6","cname":"母婴孕婴"},
            * {"cid":"afdba41a139b4320a74904485bdb7719","cname":"汽车用品"}]
            * */
            //alert(data) ;
            //获取ul标签对象--通过Jquery的方式
            //获取id="daohangUL"的标签对象
            var ul = $("#daohangUL") ;

            //alert(ul) ;
            //需要将data数据遍历出来
            //jquery对象.each([callback])
                //data--->js对象---->Jquery  $(data)jquery对象
            $(data).each(function(){
               // alert(this.cname) ;
                //拼接li标签(Jquery的文档操作)
                //Jquery对象追加方法 append("标签")
                //<li>分类名称<li>
                                /*jquery.json对象里面的key 获取value*/
                ul.append("<li><a href='${pageContext.request.contextPath}/product?methodName=findProductByPage&currentPage=1&pageSize=12&cid="+this.cid+"'>"+this.cname+"</a><span class=\"sr-only\">(current)</span></li>") ;

            })
        },"json") ;

    </script>


</html>
